package cn.doitedu.analy.groupon;

import cn.doitedu.jiaoyi.OrderInfo;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.util.Collector;

/**
 *   `id` int(20) NOT NULL AUTO_INCREMENT,
 *   `user_id` int(20) DEFAULT NULL,
 *   `product_id` int(20) DEFAULT NULL,
 *   `shop_id` int(20) DEFAULT NULL,
 *   `merchant_id` int(20) DEFAULT NULL,
 *   `order_amount` double(20,2) DEFAULT NULL,
 *   `pay_amount` double(20,2) DEFAULT NULL,
 *   `create_time` varchar(20) DEFAULT NULL,
 *   `pay_time` varchar(20) DEFAULT NULL,
 *   `pay_type` int(2) DEFAULT NULL COMMENT '1微信 2支付宝 3银联 4京东',
 *   `status` int(2) DEFAULT NULL COMMENT '0未支付 1已支付 2已退款 3未支付已失效',
 *   `number` int(20) DEFAULT NULL,
 *   `bonus_id` int(20) DEFAULT NULL,
 *   `bonus_amount` double(20,2) DEFAULT NULL,
 *   `coupon_id` int(20) DEFAULT NULL,
 *   `coupon_amount` double(20,2) DEFAULT NULL,
 *   `campain_id` int(20) DEFAULT NULL,
 *   `miaosha_id` int(20) DEFAULT NULL,
 *   `tuangou_id` int(20) DEFAULT NULL,
 */
public class GrouponMapper implements FlatMapFunction<String,GrouponEntity> {
    @Override
    public void flatMap(String s, Collector<GrouponEntity> collector) throws Exception {
        OrderInfo orderInfo = new OrderInfo();
        String[] split = s.split(",");
        orderInfo.setId(split[0]==null?null:Integer.valueOf(split[0]));
        orderInfo.setUser_id(split[1]==null?null:Integer.valueOf(split[1]));
        orderInfo.setProduct_id(split[2]==null?null:Integer.valueOf(split[2]));
        orderInfo.setShop_id(split[3]==null?null:Integer.valueOf(split[3]));
        orderInfo.setMerchant_id(split[4]==null?null:Integer.valueOf(split[4]));
        orderInfo.setOrder_amount(split[5]==null?null:Double.valueOf(split[5]));
        orderInfo.setPay_amount(split[6]==null?null:Double.valueOf(split[6]));
        orderInfo.setCreate_time(split[7]==null?null:split[7]);
        orderInfo.setPay_time(split[8]==null?null:split[8]);
        orderInfo.setPay_type(split[9]==null?null:split[9]);
        orderInfo.setStatus(split[10]==null?null:Integer.valueOf(split[10]));
        orderInfo.setNumber(split[11]==null?null:Integer.valueOf(split[11]));
        orderInfo.setBonus_id(split[12]==null?null:Integer.valueOf(split[12]));
        orderInfo.setBonus_amount(split[13]==null?null:Double.valueOf(split[13]));
        orderInfo.setCoupon_id(split[14]==null?null:Integer.valueOf(split[14]));
        orderInfo.setCoupon_amount(split[15]==null?null:Double.valueOf(split[15]));
        orderInfo.setCampain_id(split[16]==null?null:Integer.valueOf(split[16]));
        orderInfo.setMiaosha_id(split[17]==null?null:Integer.valueOf(split[17]));
        orderInfo.setTuangou_id(split[18]==null?null:Integer.valueOf(split[18]));

        GrouponEntity grouponEntity = new GrouponEntity();
        grouponEntity.setUserId(orderInfo.getUser_id()+"");
        grouponEntity.setTimes(1);

        collector.collect(grouponEntity);

    }
}
